package com.neko.Thread_Learning;

/**
 * 14、线程优先级 Thread Priority
 * ---------------------------
 *  1、测试 Priority
 * */
public class t14_Thread_Priority extends Thread {

    public static void main(String[] args) {
        // 主线程 Default Priority
        System.out.println(Thread.currentThread().getName() + " --> " + Thread.currentThread().getPriority());

        MyPriority myPriority = new MyPriority();

        Thread thread1 = new Thread(myPriority);
        Thread thread2 = new Thread(myPriority);
        Thread thread3 = new Thread(myPriority);
        Thread thread4 = new Thread(myPriority);
        Thread thread5 = new Thread(myPriority);

        // 先设置 Priority 再启动
        thread1.start();

        thread2.setPriority(1); // -1 / 11 都会报 java.lang.IllegalArgumentException 错误
        thread2.start();

        thread3.setPriority(3);
        thread3.start();

        thread4.setPriority(7);
        thread4.start();

        thread5.setPriority(Thread.MAX_PRIORITY); // Thread.MAX_PRIORITY == 10
        thread5.start();
    }

}

class MyPriority implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " --> " + Thread.currentThread().getPriority());
    }
}